package question5;

public class TrainTickt implements Runnable {
    private int ticktAmount = 100;
    @Override
    public void run() {
        while (true){
            synchronized (this){
                if(ticktAmount == 0){
                    System.out.println("该车票已售罄!");
                    break;
                }
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"=========="+ticktAmount--);
            }
        }

    }

    public static void main(String[] args) {
        Runnable tt = new TrainTickt();
        new Thread(tt,"取票机1").start();
        new Thread(tt,"取票机2").start();
        new Thread(tt,"取票机3").start();
        new Thread(tt,"取票机4").start();
        new Thread(tt,"取票机5").start();
    }
}
